package com.pb.wkflow.api.handler;

import com.pb.infra.oth.entity.common.Result;
import com.pb.wkflow.api.exception.ApprovalException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

/**
 * 全局异常类
 * @author 苗益辉
 * @date 2022/11/22 14:31
 */
@ControllerAdvice
@RestController
@Slf4j
public class ApprovalExceptionHandler {

    /**
     * ApprovalException
     * @param e e
     * @param response response
     * @return Result
     */
    @ExceptionHandler(ApprovalException.class)
    @ResponseStatus(HttpStatus.OK)
    public Result approvalException(ApprovalException e, HttpServletResponse response) {
        log.error("approvalException {}", e);
        return Result.error(e.getErrorCode(), e.getErrorMsg());
    }
}
